import { Injectable } from '@nestjs/common'
import { InjectModel } from '@nestjs/mongoose'
import { Area } from './area.schema'
import { Model } from 'mongoose'

@Injectable()
export class AreaService {

    // 模型注入
    constructor(@InjectModel(Area.name) private AreaSchema: Model<Area>) {
    }
    //添加品牌
    async addArea(body: any) {
        await this.AreaSchema.create(body)
        return "添加成功" 
    }
    //查询品牌
    async getArea(searchList:any[]) {
        let data
        if (searchList.length > 0) {
            data = await this.AreaSchema.find({ $and: searchList }) // 使用

        } else {
            data = await this.AreaSchema.find() // 使用
        }

        return data
    } 
    //修改品牌  
    async updateArea(body: any) {
        await this.AreaSchema.updateOne({ _id: body._id }, body)
        return  "修改成功"
    }
    //删除品牌
    async deleteArea(body: any) {
        await this.AreaSchema.deleteOne({ _id: body._id })
        return "删除成功"
    }

    
}